var faceoz = require('ui/faceoz');
function select_uniqute_code_from_exist_list(args) {
	//private member
	var _content_id_list = args.content_id_list;
	var _content_name_list = args.content_name_list;
	var _selected_obj_id = args.content;
	var _selected_name = args.content_value;
	var _is_selected = false;
	var _data = [];
	var _win_source = 'select_uniqute_code_from_exist_list_page';

	var win = Ti.UI.createWindow({
		title:args.title
	});
	for (var i = 0, j = _content_name_list.length; i < j; i++) {
		var row = Ti.UI.createTableViewRow({
			className : 'data_row_' + i,
			title :_content_name_list[i],
			obj_id : _content_id_list[i],
			hasCheck : (_content_id_list[i] == _selected_obj_id) ? true : false
		});
		_data.push(row);
	}
	var table_view = Ti.UI.createTableView({
		data : _data,
		style : Ti.UI.iPhone.TableViewStyle.GROUPED,
		minRowHeight : faceoz.default_table_view_row_height
	});
	win.add(table_view);
	table_view.addEventListener('click', function(e) {
		var index = e.index;
		var section = e.section;
		for (var i = 0, j = _data.length; i < j; i++) {
			section.rows[i].hasCheck = false;
		}
		section.rows[index].hasCheck = true;
		_selected_name = section.rows[index].title;
		_selected_obj_id = section.rows[index].obj_id;
		_is_selected = true;
	});

	var rightNavBtn = Titanium.UI.createButton({
		title : 'Done',
		style : Titanium.UI.iPhone.SystemButtonStyle.BORDERED
	});
	win.setRightNavButton(rightNavBtn);
	rightNavBtn.addEventListener('click', function() {
		if (_selected_obj_id != args.content) {
			Ti.App.Properties.setBool('update_unique_code_' + _win_source + '_view_flag', true);
			Ti.App.Properties.setString('update_unique_code_' + _win_source + '_view_id', _selected_obj_id);
			Ti.App.Properties.setString('update_unique_code_' + _win_source + '_view_content', _selected_name);
		}
		win.close();
	});

	var leftNavBtn = Titanium.UI.createButton({
		title : 'Back',
		style : Titanium.UI.iPhone.SystemButtonStyle.BORDERED
	});
	win.setLeftNavButton(leftNavBtn);
	leftNavBtn.addEventListener('click', function() {
		win.close();
	});
	return win;
}

module.exports = select_uniqute_code_from_exist_list;

